import time
import datetime
import pymssql
import sys
import pdb

def insert_device_to_CARONLINE(device_params):
    conn = pymssql.connect(host=r'localhost:2929', user='sa', password='safeinside', database='PGSMData', login_timeout=10)
    c = conn.cursor()

    q = "UPDATE PGSMData.dbo._users SET login=\'del%s\' WHERE login=\'dev%s\'" % (str(device_params), str(device_params))
    c.execute(q)

    conn.commit()
    conn.close()
    return device_params

def request_params():
    sys.stdout.write('Enter Device Id: \n')
    device_pcnid   = int(sys.stdin.readline().strip('\n'))
    return device_pcnid

while True:
    try:
        device_params = request_params()
        device_params = insert_device_to_CARONLINE(device_params)
        print 'device successfully removed: device_id is %s\n\n' % (str(device_params))
    except Exception, err:
        print 'device remove failed: %s' % (str(err))

